package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocCreditquerySummaryDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditquerySummary;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditquerySummaryService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditquerySummaryVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 查询记录汇总信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditquerySummaryService")
public class PbocCreditquerySummaryServiceImpl implements PbocCreditquerySummaryService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditquerySummaryServiceImpl.class);

	@Autowired
	private PbocCreditquerySummaryDao pbocCreditquerySummaryDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditquerySummary(PbocCreditquerySummaryVO inPbocCreditquerySummaryVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditquerySummaryVo.toString());
		int num = 0;
		try {
			PbocCreditquerySummary pbocCreditquerySummary = new PbocCreditquerySummary();
			beanCopy(inPbocCreditquerySummaryVo, pbocCreditquerySummary);
			num = pbocCreditquerySummaryDao.insertPbocCreditquerySummary(pbocCreditquerySummary);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditquerySummaryVO inPbocCreditquerySummaryVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditquerySummaryVo);
		int num = 0;
		try {
			PbocCreditquerySummary pbocCreditquerySummary = new PbocCreditquerySummary();
			beanCopy(inPbocCreditquerySummaryVo, pbocCreditquerySummary);
			num = pbocCreditquerySummaryDao.deleteByPk(pbocCreditquerySummary);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditquerySummaryVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditquerySummaryVO inPbocCreditquerySummaryVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditquerySummaryVo.toString());
		int num = 0;
		try {
			PbocCreditquerySummary pbocCreditquerySummary = new PbocCreditquerySummary();
			beanCopy(inPbocCreditquerySummaryVo, pbocCreditquerySummary);
			num = pbocCreditquerySummaryDao.updateByPk(pbocCreditquerySummary);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditquerySummaryVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditquerySummaryVO queryByPk(PbocCreditquerySummaryVO inPbocCreditquerySummaryVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditquerySummaryVo);
		try {
			PbocCreditquerySummary queryPbocCreditquerySummary = new PbocCreditquerySummary();
			beanCopy(inPbocCreditquerySummaryVo, queryPbocCreditquerySummary);
			PbocCreditquerySummary queryRslPbocCreditquerySummary = pbocCreditquerySummaryDao.queryByPk(queryPbocCreditquerySummary);
			if (Objects.nonNull(queryRslPbocCreditquerySummary)) {
				PbocCreditquerySummaryVO outPbocCreditquerySummaryVo = beanCopy(queryRslPbocCreditquerySummary, new PbocCreditquerySummaryVO());
				logger.debug("当前查询结果为:"+ outPbocCreditquerySummaryVo.toString());
				return outPbocCreditquerySummaryVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
	
	/**
	 * @description:根据报告编号查询
	 * @param fid
	 * @return
	 * @date:2018年12月27日 下午8:44:32
	 * @author:hengyh
	 */
	@Override
	public PbocCreditquerySummaryVO queryByFId(String fid)  throws Exception {
		logger.debug("当前查询参数信息为:"+ fid);
		PbocCreditquerySummary queryRslPbocCreditquerySummary = 
				pbocCreditquerySummaryDao.queryByFId(fid);
		if (Objects.nonNull(queryRslPbocCreditquerySummary)) {
			PbocCreditquerySummaryVO outPbocCreditquerySummaryVo = beanCopy(queryRslPbocCreditquerySummary, new PbocCreditquerySummaryVO());
			logger.debug("当前查询结果为:"+ outPbocCreditquerySummaryVo.toString());
			return outPbocCreditquerySummaryVo;
		} else {
			logger.debug("当前查询结果为空!");
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditquerySummaryVO> queryAllOwner(PbocCreditquerySummaryVO pbocCreditquerySummaryVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditquerySummaryVO> list = null;
		try {
			List<PbocCreditquerySummary> pbocCreditquerySummarys = pbocCreditquerySummaryDao.queryAllOwnerByPage(pbocCreditquerySummaryVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditquerySummarys.size());
			pageSet(pbocCreditquerySummarys, pbocCreditquerySummaryVo);
			list = (List<PbocCreditquerySummaryVO>) beansCopy(pbocCreditquerySummarys, PbocCreditquerySummaryVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditquerySummaryVO> queryAllCurrOrg(PbocCreditquerySummaryVO pbocCreditquerySummaryVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditquerySummary> pbocCreditquerySummarys = pbocCreditquerySummaryDao.queryAllCurrOrgByPage(pbocCreditquerySummaryVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditquerySummarys.size());
		List<PbocCreditquerySummaryVO> list = null;
		try {
			pageSet(pbocCreditquerySummarys, pbocCreditquerySummaryVo);
			list = (List<PbocCreditquerySummaryVO>) beansCopy(pbocCreditquerySummarys, PbocCreditquerySummaryVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditquerySummaryVO> queryAllCurrDownOrg(PbocCreditquerySummaryVO pbocCreditquerySummaryVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditquerySummary> pbocCreditquerySummarys = pbocCreditquerySummaryDao.queryAllCurrDownOrgByPage(pbocCreditquerySummaryVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditquerySummarys.size());
		List<PbocCreditquerySummaryVO> list = null;
		try {
			pageSet(pbocCreditquerySummarys, pbocCreditquerySummaryVo);
			list = (List<PbocCreditquerySummaryVO>) beansCopy(pbocCreditquerySummarys, PbocCreditquerySummaryVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

}
